import request from '../../utils/request'
import constants from '../../utils/Constants'

/**
 * 获取采购合同信息列表
 * @param page
 * @returns {Promise.<void>}
 */
export async function getAgreementApprovalList({id, page}) {
    return request(apiPath.zbtie + "/api/businessagreement/"+ id +"/approval", {
        method: 'get',
        data: {page: page.page, size: page.size}
    });
}

/**
 * 多条件分页查询采购合同
 * @param cstid
 * @param status
 * @param page
 * @returns {Promise.<void>}
 */
export async function getAgreementlList({ cstid, status, page, type}) {
    if("approval" == type ){
        type = "/api/businessagreement/page";
    }else{
        type = "/api/"+ cstid  +"/businessagreement/page";
    }

    return request(apiPath.zbtie + type, {
        method: 'get',
        data: {status, page: page.page, size: page.size}
    });
}


/**
 * 增加采购合同
 * @param title
 * @param content
 * @param cstid
 * @param url
 * @returns {Promise.<void>}
 */
export async function addAgreement({ title, content, cstid, url,method}) {
    return request(apiPath.zbtie + "/api/businessagreement", {
        method: 'post',
        data: {title, content, cstid, url,method}
    });
}


/**
 * 更新采购合同
 * @param id
 * @param title
 * @param content
 * @param cstid
 * @param url
 * @returns {Promise.<void>}
 */
export async function updateAgreement({id, title, content, cstid, url, status}) {
    return request(apiPath.zbtie + "/api/businessagreement", {
        method: 'put',
        data: {id, title, content, cstid, url, status}
    });
}


/**
 * 获取采购合同详情
 * @param id
 * @returns {Promise.<void>}
 */
export async function getAgreementById({id}) {
    return request(apiPath.zbtie + "/api/businessagreement/"+ id, {
        method: 'get'
    });
}



/**
 * 删除采购合同
 * @param id
 * @returns {Promise.<void>}
 */
export async function deleteAgreementById({id}) {
    return request(apiPath.zbtie + "/api/businessagreement/"+ id, {
        method: 'delete'
    });
}


/**
 * 审核
 * @param id
 * @param approvalresult
 * @param approvalmemo
 * @returns {Promise.<void>}
 */
export async function agreementApproval({id, approvalresult, approvalmemo}) {
    let businesstype = "businessagreement";
    let entityid = id;
    return request(apiPath.zbtie + "/api/businessagreement/" + id + "/approval", {
        method: 'post',
        data: {
            id, approvalresult, approvalmemo, businesstype, entityid, appCode: constants.APPCODE
        }
    });
}

/**
 * 获取当前工作流审核节点
 * @param id
 * @returns {Promise.<void>}
 */
export async function getCurrentNodeDetail({id, code}) {
    return request(apiPath.zbtie + "/api/task/currentNode/"+ id, {
        method: 'get',
        data: {
            code, appCode: constants.APPCODE
        }
    });
}



